package objs;

import service.Play;
import util.Utils;

import java.awt.*;

public class Bossobj extends Pojo{
    private int state =0;
    //考虑每个Boss都有自己的生命值，life不能使用public权限
    private int life=1000;
    private int back_rX=800;
    private int back_lx=200;

    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public Bossobj() {
    }

    public Bossobj(Image image, int x, int y, int width, int height, double speed, Play frame) {
        super(image, x, y, width, height, speed, frame);
    }

    @Override
    public void paintSelf(Graphics gImage) {
//        gImage.drawImage(image,x,y,width,height,null);
        switch(state){
            case 0:
                gImage.drawImage(Play.img_Boss1,x,y,width,height,null);
                state=1;
                break;
            case 1:
                gImage.drawImage(Play.img_Boss2,x,y,width,height,null);
                state=0;
                break;
            default:
        }
        if(x>this.back_rX){
            speed=-Math.abs(speed);
            this.back_rX+=50;
        }
        if(x<this.back_lx){
            speed=Math.abs(speed);
            this.back_lx-=50;
        }
        x+=speed;
        for(int i=0;i<Play.bulletobjList.size();i++){
            if(this.getRec().intersects(Play.bulletobjList.get(i).getRec())){
                this.life--;
//                System.out.println(this.life);
                gImage.drawImage(Play.img_Boss_Hit,x,y,width,height,null);
                Play.removeList.add(Play.bulletobjList.get(i));
                Play.bulletobjList.remove(Play.bulletobjList.get(i));
            }
        }

        if(this.life<=0){
            gImage.drawImage(Play.img_Boss_Down1,x,y,width,height,null);
            gImage.drawImage(Play.img_Boss_Down2,x,y,width,height,null);
            gImage.drawImage(Play.img_Boss_Down3,x,y,width,height,null);
            gImage.drawImage(Play.img_Boss_Down4,x,y,width,height,null);
            gImage.drawImage(Play.img_Boss_Down5,x,y,width,height,null);
            gImage.drawImage(Play.img_Boss_Down6,x,y,width,height,null);
            Play.bossobjList.remove(this);
            Play.removeList.add(this);
        }
        gImage.setColor(Color.green);
        gImage.fillRect(x,y+30,width,30);
        gImage.setColor(Color.blue);
        gImage.fillRect(x,y+30,this.life*width/1000,30);
        Utils.drawWord(gImage,"生命值"+this.life,Color.red,30,x,y+60);
    }
}
